/**
 *
 * Created by chuaiqing on 16/1/13.
 */
'use strict';
angular.module('mk.services', [])
    .service('HttpRequestService', ['$http', '$q', 'Settings', function ($http, $q, Settings) {
        return {
            doPost: function (url, postParams) {
                //
                var context_path = "";
                if (Settings != undefined && Settings != null) {
                    var context = Settings.Context || {};
                    context_path = context.path || "";
                }
                var postUrl = context_path + url;
                var deferred = $q.defer();
                return $http.post(postUrl, postParams)
                    .success(function (result) {
                        deferred.resolve(result);
                    })
                    .error(function(error) {
                        deferred.reject(error);
                    });
                return deferred.promise;
            },
            doGet: function (url) {
                //
                var context_path = "";
                if (Settings != undefined && Settings != null) {
                    var context = Settings.Context || {};
                    context_path = context.path || "";
                }
                var getUrl = context_path + url;
                var deferred = $q.defer();
                return $http.get(getUrl)
                    .success(function (result) {
                        deferred.resolve(result);
                    })
                    .error(function (error) {
                        deferred.reject(error);
                    });
                return deferred.promise;
            }
        };
    }]);